/* 
 * Copyright 2014 Josef Hertl.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package caetus.modelChecking.variable;

import java.util.Comparator;

/**
 *
 * @author Josef Hertl
 */
public class ModelVariableTypeComparator implements Comparator<String> {

    @Override
    public int compare(String o1, String o2) {
        int i1 = valueOfString(o1);
        int i2 = valueOfString(o2);
        if (i1 >= 0 || i2 >=0) {
            return i2 - i1;
        } else {
            return o1.compareTo(o2);
        }
    }

    /**
     * Gives value to the string - higher value means the string is higher. This
     * is used to order the variables in the variables list.
     *
     * @param input The input string
     * @return Value of the string that means how high it is.
     */
    private int valueOfString(String input) {
        if (input.contains("agent")) {
            return 20;
        } else if (input.equals("public_key")) {
            return 19;
        } else if (input.contains("inv(public_key)")) {
            return 18;
        } else if (input.equals("symmetric_key")) {
            return 17;
        } else if (input.contains("bool")) {
            return 10;
        } else if (input.contains("message")) {
            return 5;
        } else if (input.contains("nat")) {
            return 4;
        } else if (input.contains("channel")) {
            return 2;
        } else if (input.contains("protocol")) {
            return 1;
        } else if (input.contains("text")) {
            return 0;
        } else {
            return -1; //when the string is a complex variable type
        }
    }
}
